const marqueeText = document.getElementById('marquee-text');
const marqueeInput = document.getElementById('marquee-input');
let position = marqueeText.parentElement.offsetWidth;
const speed = 2; // 控制字幕滚动速度

function initMarquee() {
    position = marqueeText.parentElement.offsetWidth;
    scrollMarquee();
}

function scrollMarquee() {
    position -= speed;
    if (position < -marqueeText.offsetWidth) {
        position = marqueeText.parentElement.offsetWidth;
    }
    marqueeText.style.transform = `translateX(${position}px)`;
    requestAnimationFrame(scrollMarquee);
}

// 页面加载完成后启动字幕滚动
window.addEventListener('load', initMarquee);

// 监听输入框变化更新字幕内容
marqueeInput.addEventListener('input', () => {
    marqueeText.textContent = marqueeInput.value || "又是美好的一天";
});
